package com.zzptc.myk.myapplication.Fragment;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.zzptc.myk.myapplication.Adapter.UserAdapter;
import com.zzptc.myk.myapplication.Bean.User;
import com.zzptc.myk.myapplication.MainActivity;
import com.zzptc.myk.myapplication.R;

import org.litepal.LitePal;

import java.util.ArrayList;
import java.util.List;

public class FirsFragment extends Fragment {
    private ListView lv;
    private UserAdapter adapter;
    List<User> usersList=new ArrayList<>();
    public FirsFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.fragment_firs, container, false);
        initView(view);
        setListrener();
        return view;
    }
    private void setListrener() {
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                showToast("你点击了"+usersList.get(position));
            }
        });
    }

    private void initView(View view) {
        usersList= LitePal.findAll(User.class);
       lv=view.findViewById(R.id.lv);
       adapter=new UserAdapter(getContext(),R.layout.uwer_list,usersList);
        lv.setAdapter(adapter);
    }
    private void showToast(String str){
        Toast.makeText(getContext(),str,Toast.LENGTH_SHORT).show();
    }

}
